package pl.grabar.clinic.core.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Tworznie połaczenia z bazą na podstawie ustawień w pliku: persistance.xml
 * 
 * @author db
 *
 */
public class EntityManagerFactoryService {
	
	private static final Log LOG = LogFactory.getLog(EntityManagerFactoryService.class);
	
	private EntityManager entityManager;
	
	private EntityManagerFactory entityManagerFactory;

	public void entityManagFactCon() {
		setUp();
		LOG.info("Tworze EntityManagerFactory");
		this.entityManager = entityManagerFactory.createEntityManager();
		LOG.info("Utworzylem EntityManagerFactory");
	}

	protected void setUp() {
		entityManagerFactory = Persistence.createEntityManagerFactory("jpaClinic");
	}

	public void closeEMF() {
		entityManagerFactory.close();
	}

	public EntityManager getEntityManag() {
		return entityManager;
	}

}
